package product;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.print.PrinterException;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;

import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.OrientationRequested;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableRowSorter;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.ImageIcon;

public class SaleList extends JInternalFrame {

	DecimalFormat df = new DecimalFormat("###,###,###.##");
	String[] column = { "aa", "bb" }; // 컬럼명
	String FilePath = "c:\\data.xls"; // 파일 경로 및 파일명
	String SheetName = "test"; // 시트 이름
	String[][] data = new String[4][2];// 데이터
	ButtonGroup bg = new ButtonGroup();
	ButtonGroup bg2 = new ButtonGroup();
	DefaultTableModel model;
	Connection con;
	ResultSetMetaData rsm;
	SaleUpdate update;
	ProductMain5 m;
	int b;

	private JPanel panel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JTextField findStr;
	private JButton button;
	private JScrollPane scrollPane;
	private JTable table;
	private JButton btnSave;
	private JButton btnPrint;
	private JPanel panel_3;
	private JPanel panel_4;
	private JLabel lblNewLabel;
	private JPanel panel_5;
	private JPanel panel_6;
	private JComboBox com;
	private JPanel panel_7;
	private JLabel lblNewLabel_1;
	private JComboBox comm;
	private JLabel lblNewLabel_2;
	private JPanel panel_10;
	private JPanel panel_11;
	private JLabel lblNewLabel_3;
	private JPanel panel_12;
	private JPanel panel_13;
	private JPanel panel_14;
	private JPanel panel_15;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JButton btnNewButton_2;
	private JButton btnNewButton_3;
	private JButton btnNewButton_4;
	private JPanel panel_16;
	private JComboBox com1;
	private JLabel label_1;
	private JComboBox com2;
	private JLabel label_2;
	private JComboBox com3;
	private JLabel label_3;

	private JPanel panel_8;
	private JPanel panel_9;
	private JPanel panel_17;
	private JPanel panel_18;
	private JLabel lblNewLabel_4;
	private JPanel panel_19;
	private JPanel panel_20;
	private JRadioButton btn1;
	private JRadioButton btn2;
	private JPanel panel_21;
	private JLabel label_4;
	private JPanel panel_22;
	private JPanel panel_23;
	private JRadioButton btn3;
	private JRadioButton btn4;
	private JPanel panel_24;
	private JPanel panel_25;
	// ///페이지처리////////
	int count = 0;// 검색된 수
	int page = 1;// 페이지 번호
	int no = 1;// 글번호
	int btnCnt = 11;
	String sql = "";
	int i = 0;
	private JPanel panel_26;
	private JLabel lblNewLabel_5;
	private JPanel panel_27;
	private JPanel panel_28;
	private JComboBox com4;
	private JLabel label_5;
	private JComboBox com5;
	private JLabel label_6;
	private JComboBox com6;
	private JLabel label_7;
	private JPanel panel_30;
	// ////////////////////
	Date now = new Date();

	SimpleDateFormat day = new SimpleDateFormat("yyyy-MM-dd");
	Calendar currentCalendar = Calendar.getInstance();
	DecimalFormat dv = new DecimalFormat("00");
	String Year;
	String Month;
	String Day;
	String Date;
	String Date1;
	String find;
	String Date2;
	String temp;
	String[] h = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
			"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
			"22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
	String[] e = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
			"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
			"22", "23", "24", "25", "26", "27", "28", "29", "30", };
	String[] s = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
			"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
			"22", "23", "24", "25", "26", "27", "28" };
	String[] s2 = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
			"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
			"22", "23", "24", "25", "26", "27", "28", "29" };
	int control = 0;
	int control2 = 0;
	int control3 = 0;
	private JButton btnNewButton_6;
	private JButton button_1;

	public SaleList(Connection con, ProductMain5 ma) {
		super("판매 조회", true, true, true, true);
		this.con = con;
		this.m = ma;
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameClosed(InternalFrameEvent arg0) {
				m.saleList = null;
			}
		});
		setBounds(100, 100, 673, 456);

		getContentPane().add(getPanel_30(), BorderLayout.CENTER);
		input();

		com.setSelectedItem(day.format(now).substring(0, 4));
		com1.setSelectedItem(day.format(now).substring(0, 4));
		com2.setSelectedItem(day.format(now).substring(5, 7));
		com3.setSelectedItem(day.format(now).substring(8, 10));
		today();
	}

	public void input() {
		com1.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 2)));
		com1.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 1)));
		com1.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)))));
		com1.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) + 1)));
		com.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 2)));
		com.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 1)));
		com.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)))));
		com.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) + 1)));
		com4.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 2)));
		com4.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) - 1)));
		com4.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)))));
		com4.addItem(Integer.toString((Integer.parseInt(day.format(now)
				.substring(0, 4)) + 1)));
	}

	public void nextday() {
		Date1 = (String) com1.getSelectedItem() + "/"
				+ (String) com2.getSelectedItem() + "/"
				+ (String) com3.getSelectedItem();
		find = findStr.getText();
		Date2 = (String) com4.getSelectedItem() + "/"
				+ (String) com5.getSelectedItem() + "/"
				+ (String) com6.getSelectedItem();
		sql = "select to_date(?, 'YYYY/MM/DD')+1 from dual";
		try {
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, Date2);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next()) {
				temp = rs.getString(1);
			}
		} catch (Exception ev) {
		}
	}

	private JPanel getPanel_30() {
		if (panel_30 == null) {
			panel_30 = new JPanel();

			panel_30.setLayout(new BorderLayout(0, 0));
			panel_30.add(getPanel(), BorderLayout.SOUTH);
			panel_30.add(getPanel_1(), BorderLayout.CENTER);

		}
		return panel_30;
	}

	// ///////////////////////////////////////////

	// ////////////////////////
	public void search() {
		try {
			nextday();
			if (btn3.isSelected()) {
				sql = "select s.sa_no, s.sa_pro_code, c.pro_nm, s.sa_ea, s.sa_price, s.sa_reg_date, m.irum "
						+ " from sale s inner join code c on c.pro_code = s.sa_pro_code inner "
						+ " join memberdata m on s.sa_reg_mem=m.memberid "
						+ "where s.sa_reg_date between ? and ? "
						+ " and (s.sa_pro_code like ? or c.pro_nm like ?) "
						+ " order by s.sa_no desc ";
			} else {
				sql = "select s.sa_no, s.sa_pro_code, c.pro_nm, s.sa_ea, s.sa_price, s.sa_reg_date, m.irum "
						+ " from sale s inner join code c on c.pro_code = s.sa_pro_code inner "
						+ " join memberdata m on s.sa_reg_mem=m.memberid "
						+ "where s.sa_reg_date between ? and ? "
						+ " and (s.sa_pro_code like ? or c.pro_nm like ?) "
						+ " order by s.sa_no asc";
			}

			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, Date1);
			pstmt.setString(2, temp.substring(0, 11));
			pstmt.setString(3, "%" + find + "%");
			pstmt.setString(4, "%" + find + "%");
			ResultSet rs = pstmt.executeQuery();
			rsm = rs.getMetaData();
			Vector col = new Vector<>();
			col.add("판매번호");
			col.add("제품코드");
			col.add("제품이름");
			col.add("판매수량");
			col.add("판매가격");
			col.add("판매일");
			col.add("판매자");
			model = new DefaultTableModel(col, 0) {
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			table.setModel(model);
			table.setRowSorter(new TableRowSorter(model));
			DefaultTableCellRenderer Center = new DefaultTableCellRenderer();
			Center.setHorizontalAlignment(SwingConstants.CENTER);// 우측 정렬
			TableColumnModel tcmSchedule = table.getColumnModel();
			DefaultTableCellRenderer Right = new DefaultTableCellRenderer();
			Right.setHorizontalAlignment(SwingConstants.RIGHT);// / 우측
			table.getColumn("판매수량").setPreferredWidth(50);
			table.getColumn("판매자").setPreferredWidth(40);
			table.getTableHeader().setReorderingAllowed(false);
			table.getTableHeader().setResizingAllowed(false);
			for (int i = 0; i <= 6; i++) {
				if (i == 4 || i == 3)
					tcmSchedule.getColumn(i).setCellRenderer(Right);
				else
					tcmSchedule.getColumn(i).setCellRenderer(Center);
			}
			while (rs.next()) {
				Vector d = new Vector<>();
				String dv = "";

				for (int i = 1; i <= rsm.getColumnCount(); i++) {
					if (i == 4) {
						String str = df
								.format(Integer.parseInt(rs.getString(i)));
						d.add(str);
					} else if (i == 5) {
						String str = df
								.format(Integer.parseInt(rs.getString(i)))
								+ "원";
						d.add(str);
					} else if (i == 6) {
						d.add(rs.getString(i).substring(0, 11));
					} else
						d.add(rs.getString(i));
				}
				d.add(dv);
				model.addRow(d);

			}
			rs.close();
			pstmt.close();
			b = 1;
			if (model.getRowCount() == 0)
				JOptionPane.showMessageDialog(null, "해당 정보는 존재하지 않습니다.");

		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "조회기간을 확인해 주세요");
		}
	}

	private boolean search2() {
		try {
			nextday();

			String sql = "select c.pro_code,c.pro_nm,sum(s.sa_ea), sum(s.sa_price) from sale s inner join"
					+ " code c on c.pro_code = s.sa_pro_code where (s.sa_pro_code like ? or c.pro_nm like ?)"
					+ " and s.sa_reg_date between ? and ?  group by c.pro_code, c.pro_nm order by c.pro_code";
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, "%" + find + "%");
			pstmt.setString(2, "%" + find + "%");
			pstmt.setString(3, Date1);
			pstmt.setString(4, temp.substring(0, 11));
			ResultSet rs = pstmt.executeQuery();

			rsm = rs.getMetaData();
			Vector col = new Vector<>();
			col.add("제품코드");
			col.add("제품이름");
			col.add("판매수량");
			col.add("판매가격");
			model = new DefaultTableModel(col, 0) {
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			table.setModel(model);
			table.setRowSorter(new TableRowSorter(model));
			DefaultTableCellRenderer Center = new DefaultTableCellRenderer();
			Center.setHorizontalAlignment(SwingConstants.CENTER);// 가운데 정렬
			TableColumnModel tcmSchedule = table.getColumnModel();
			DefaultTableCellRenderer Right = new DefaultTableCellRenderer();
			Right.setHorizontalAlignment(SwingConstants.RIGHT);// 우측 정렬
			table.getTableHeader().setReorderingAllowed(false);
			table.getTableHeader().setResizingAllowed(false);
			for (int i = 0; i <= 1; i++) {
				tcmSchedule.getColumn(i).setCellRenderer(Center);
			}
			tcmSchedule.getColumn(3).setCellRenderer(Right);
			tcmSchedule.getColumn(2).setCellRenderer(Right);
			while (rs.next()) {
				Vector d = new Vector<>();
				for (int i = 1; i <= rsm.getColumnCount(); i++) {
					if (i == 3) {
						d.add(df.format(Integer.parseInt(rs.getString(i))));

					} else if (i == 4)
						d.add(df.format(Integer.parseInt(rs.getString(i)))
								+ "원");
					else {
						d.add(rs.getString(i));
					}
				}
				model.addRow(d);
			}
			rs.close();
			pstmt.close();
			b = 2;
			if (model.getRowCount() == 0)
				JOptionPane.showMessageDialog(null, "해당 정보는 존재하지 않습니다.");
			return true;
		} catch (Exception e) {
			System.out.println("예외사항:" + e.getMessage());
			return false;
		}
	}

	public void print() {

		try {
			MessageFormat headerFormat = new MessageFormat("프린트테스트"); // 타이틀.
			MessageFormat footerFormat = new MessageFormat("- {0} -"); // 페이지.자동증가된다.
			PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); // 프린트설정.(용지를
			// 가로로
			// 할지
			// 세로로 할지.)
			aset.add(OrientationRequested.LANDSCAPE); // (용지 디폴트를
			// 가로로.
			table.print(JTable.PrintMode.FIT_WIDTH, headerFormat, footerFormat,
					true, aset, true); // JTable 붙인다.
		} catch (PrinterException pe) {
			System.err.println("Error printing: " + pe.getMessage());
		}

	}

	public void MouseC() {
		int index = table.getSelectedRow();
		String sno = (String) table.getValueAt(index, 0);
		String c = (String) table.getValueAt(index, 1);
		String n = (String) table.getValueAt(index, 2);
		String p = (String) table.getValueAt(index, 4);
		String e = (String) table.getValueAt(index, 3);

		if (update == null) {
			update = new SaleUpdate(m, con, this);
			m.getContentPane().add(update);
			update.setVisible(true);
			update.setBounds(0, 0, 470, 410);
		}
		update.setData(sno, c, n, p, e);
		findStr.requestFocus();
	}

	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setPreferredSize(new Dimension(10, 30));
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getPanel_24(), BorderLayout.EAST);
			panel.add(getPanel_26(), BorderLayout.CENTER);
		}
		return panel;
	}

	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getPanel_2(), BorderLayout.NORTH);
			panel_1.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel_1;
	}

	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel_3(), BorderLayout.CENTER);
			panel_2.add(getPanel_9(), BorderLayout.SOUTH);
			panel_2.add(getPanel_17(), BorderLayout.NORTH);
		}
		return panel_2;
	}

	private JTextField getFindStr() {

		if (findStr == null) {
			findStr = new JTextField();
			findStr.addKeyListener(new KeyAdapter() {
				@Override
				public void keyPressed(KeyEvent e) {
					int key = e.getKeyCode();
					if (key == KeyEvent.VK_CONTROL) {
						control = key;
					}
					if (key == KeyEvent.VK_P) {
						control2 = key;
					}
					if (key == KeyEvent.VK_S) {
						control2 = key;
					}
					if (control == 17 && control2 == 80) {
						print();
					}
					if (control == 17 && control2 == 83) {
						ExcelSave(table);
					}
				}

				@Override
				public void keyReleased(KeyEvent e) {
					control = 0;
					control2 = 0;
					control3 = 0;
					if (e.getKeyCode() == KeyEvent.VK_ENTER) {
						sear();
					}
				}

			});

			findStr.setRequestFocusEnabled(true);
			findStr.setPreferredSize(new Dimension(6, 30));
			findStr.setColumns(25);
		}
		return findStr;
	}

	private JButton getButton() {
		if (button == null) {
			button = new JButton("조회");
			button.setPreferredSize(new Dimension(57, 30));
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					sear();
				}
			});
		}
		return button;
	}

	public void sear() {

		if (btn2.isSelected())
			search();
		else if (btn1.isSelected())
			search2();
		findStr.requestFocus();
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}

	private JTable getTable() {
		if (table == null) {
			table = new JTable(model);
			table.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent arg0) {
					if (b == 1) {
						MouseC();
					}
				}
			});
		}
		return table;
	}

	private JButton getBtnSave() {
		if (btnSave == null) {
			btnSave = new JButton("저장");
			btnSave.setPreferredSize(new Dimension(70, 25));
			btnSave.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					ExcelSave(table);
				}
			});
		}
		return btnSave;
	}

	private JButton getBtnPrint() {
		if (btnPrint == null) {
			btnPrint = new JButton("인쇄");
			btnPrint.setPreferredSize(new Dimension(70, 25));
			btnPrint.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					print();
				}
			});
		}
		return btnPrint;
	}

	private JPanel getPanel_3() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setLayout(new BorderLayout(0, 0));
			panel_3.add(getPanel_4(), BorderLayout.SOUTH);
			panel_3.add(getLblNewLabel(), BorderLayout.WEST);
			panel_3.add(getPanel_5(), BorderLayout.CENTER);
		}
		return panel_3;
	}

	private JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setLayout(new BorderLayout(0, 0));
			panel_4.add(getPanel_10(), BorderLayout.WEST);
			panel_4.add(getPanel_12(), BorderLayout.CENTER);
		}
		return panel_4;
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("월별조회");
			lblNewLabel.setBackground(Color.LIGHT_GRAY);
			lblNewLabel.setFont(new Font("나눔고딕코딩", Font.PLAIN, 18));
			lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel.setPreferredSize(new Dimension(90, 30));
		}
		return lblNewLabel;
	}

	private JPanel getPanel_5() {
		if (panel_5 == null) {
			panel_5 = new JPanel();
			panel_5.setLayout(new BorderLayout(0, 0));
			panel_5.add(getPanel_6(), BorderLayout.WEST);
		}
		return panel_5;
	}

	private JPanel getPanel_6() {
		if (panel_6 == null) {
			panel_6 = new JPanel();
			panel_6.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			panel_6.add(getCom());
			panel_6.add(getPanel_7());
			panel_6.add(getComm());
			panel_6.add(getLblNewLabel_2());
		}
		return panel_6;
	}

	private JComboBox getCom() {
		if (com == null) {
			com = new JComboBox();
			com.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					com1.setSelectedItem(com.getSelectedItem());
					com4.setSelectedItem(com.getSelectedItem());
					com2.setSelectedItem(comm.getSelectedItem());
					com3.setSelectedItem("01");
					com5.setSelectedItem(comm.getSelectedItem());
					int a = com6.getItemCount();
					com6.setSelectedIndex(a - 1);
				}

			});
			com.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
			com.setPreferredSize(new Dimension(70, 21));
		}
		return com;
	}

	private JPanel getPanel_7() {
		if (panel_7 == null) {
			panel_7 = new JPanel();
			panel_7.setLayout(new BorderLayout(0, 0));
			panel_7.add(getLblNewLabel_1(), BorderLayout.WEST);
		}
		return panel_7;
	}

	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("년");
			lblNewLabel_1.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return lblNewLabel_1;
	}

	private JComboBox getComm() {
		if (comm == null) {
			comm = new JComboBox();
			comm.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					com2.setSelectedItem(comm.getSelectedItem());
					com3.setSelectedItem("01");
					com5.setSelectedItem(comm.getSelectedItem());
					int a = com6.getItemCount();
					com6.setSelectedIndex(a - 1);
				}
			});
			comm.setPreferredSize(new Dimension(50, 21));
			comm.setModel(new DefaultComboBoxModel(
					new String[] { "01", "02", "03", "04", "05", "06", "07",
							"08", "09", "10", "11", "12" }));
			comm.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return comm;
	}

	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("월");
			lblNewLabel_2.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return lblNewLabel_2;
	}

	private JPanel getPanel_10() {
		if (panel_10 == null) {
			panel_10 = new JPanel();
			panel_10.setLayout(new BorderLayout(0, 0));
			panel_10.add(getPanel_11(), BorderLayout.WEST);
		}
		return panel_10;
	}

	private JPanel getPanel_11() {
		if (panel_11 == null) {
			panel_11 = new JPanel();
			panel_11.setPreferredSize(new Dimension(90, 60));
			panel_11.setLayout(new BorderLayout(0, 0));
			panel_11.add(getLblNewLabel_3());
		}
		return panel_11;
	}

	private JLabel getLblNewLabel_3() {
		if (lblNewLabel_3 == null) {
			lblNewLabel_3 = new JLabel("조회기간");
			lblNewLabel_3.setFont(new Font("나눔고딕코딩", Font.PLAIN, 18));
			lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel_3.setPreferredSize(new Dimension(60, 30));
		}
		return lblNewLabel_3;
	}

	private JPanel getPanel_12() {
		if (panel_12 == null) {
			panel_12 = new JPanel();
			panel_12.setPreferredSize(new Dimension(150, 10));
			panel_12.setLayout(new BorderLayout(0, 0));
			panel_12.add(getPanel_13(), BorderLayout.NORTH);
			panel_12.add(getPanel_14(), BorderLayout.CENTER);
		}
		return panel_12;
	}

	private JPanel getPanel_13() {
		if (panel_13 == null) {
			panel_13 = new JPanel();
			panel_13.setPreferredSize(new Dimension(30, 30));
			panel_13.setLayout(new BorderLayout(0, 0));
			panel_13.add(getPanel_15(), BorderLayout.WEST);
		}
		return panel_13;
	}

	private JPanel getPanel_14() {
		if (panel_14 == null) {
			panel_14 = new JPanel();
			panel_14.setPreferredSize(new Dimension(10, 30));
			panel_14.setLayout(new BorderLayout(0, 0));
			panel_14.add(getPanel_16(), BorderLayout.WEST);
			panel_14.add(getPanel_8(), BorderLayout.CENTER);
		}
		return panel_14;
	}

	private JPanel getPanel_15() {
		if (panel_15 == null) {
			panel_15 = new JPanel();
			panel_15.add(getBtnNewButton());
			panel_15.add(getBtnNewButton_1());
			panel_15.add(getBtnNewButton_2());
			panel_15.add(getBtnNewButton_3());
			panel_15.add(getBtnNewButton_4());
		}
		return panel_15;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("당일");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					today();
					com1.setSelectedItem(day.format(now).substring(0, 4));
					com2.setSelectedItem(day.format(now).substring(5, 7));
					com3.setSelectedItem(day.format(now).substring(8, 10));
					findStr.requestFocus();
				}
			});
			btnNewButton.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
			btnNewButton.setPreferredSize(new Dimension(70, 25));
		}
		return btnNewButton;
	}

	public void today() {
		com4.setSelectedItem(day.format(now).substring(0, 4));
		com5.setSelectedItem(day.format(now).substring(5, 7));
		com6.setSelectedItem(day.format(now).substring(8, 10));
	}

	public void month(int a) {
		currentCalendar.add(currentCalendar.DATE, -a);
		Year = Integer.toString(currentCalendar.get(Calendar.YEAR));
		Month = dv.format(currentCalendar.get(Calendar.MONTH) + 1);
		Day = dv.format(currentCalendar.get(Calendar.DATE));
		com1.setSelectedItem(Year);
		com2.setSelectedItem(Month);
		com3.setSelectedItem(Day);
		currentCalendar.add(currentCalendar.DATE, +a);
		findStr.requestFocus();
	}

	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("1주일");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					today();
					month(7);
				}
			});
			btnNewButton_1.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
			btnNewButton_1.setPreferredSize(new Dimension(70, 25));
		}
		return btnNewButton_1;
	}

	private JButton getBtnNewButton_2() {
		if (btnNewButton_2 == null) {
			btnNewButton_2 = new JButton("1개월");
			btnNewButton_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					today();
					month(31);
				}
			});
			btnNewButton_2.setPreferredSize(new Dimension(70, 23));
			btnNewButton_2.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return btnNewButton_2;
	}

	private JButton getBtnNewButton_3() {
		if (btnNewButton_3 == null) {
			btnNewButton_3 = new JButton("3개월");
			btnNewButton_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					today();
					month(92);

				}
			});
			btnNewButton_3.setPreferredSize(new Dimension(70, 23));
			btnNewButton_3.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return btnNewButton_3;
	}

	private JButton getBtnNewButton_4() {
		if (btnNewButton_4 == null) {
			btnNewButton_4 = new JButton("6개월");
			btnNewButton_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					today();
					month(184);

				}
			});
			btnNewButton_4.setPreferredSize(new Dimension(70, 23));
			btnNewButton_4.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return btnNewButton_4;
	}

	private JPanel getPanel_16() {
		if (panel_16 == null) {
			panel_16 = new JPanel();
			panel_16.add(getCom1());
			panel_16.add(getLabel_1());
			panel_16.add(getCom2());
			panel_16.add(getLabel_2());
			panel_16.add(getCom3());
			panel_16.add(getLabel_3());
			panel_16.add(getBtnNewButton_6());
		}
		return panel_16;
	}

	private JComboBox getCom1() {
		if (com1 == null) {
			com1 = new JComboBox();
			com1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (Integer.parseInt((String) com1.getSelectedItem()) % 4 == 0) {
						if (com2.getSelectedItem().equals("02")) {
							com3.setModel(new DefaultComboBoxModel<>(s2));
						}
					} else
						com3.setModel(new DefaultComboBoxModel<>(s));

				}
			});
			com1.setPreferredSize(new Dimension(70, 25));
			com1.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return com1;
	}

	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("년");
			label_1.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_1;
	}

	private JComboBox getCom2() {
		if (com2 == null) {
			com2 = new JComboBox();
			com2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if (com2.getSelectedItem().equals("01")
							|| com2.getSelectedItem().equals("03")
							|| com2.getSelectedItem().equals("05")
							|| com2.getSelectedItem().equals("07")
							|| com2.getSelectedItem().equals("08")
							|| com2.getSelectedItem().equals("10")
							|| com2.getSelectedItem().equals("12")) {
						com3.setModel(new DefaultComboBoxModel<>(h));
					} else if (com2.getSelectedItem().equals("02")) {

						if (Integer.parseInt((String) com1.getSelectedItem()) % 4 == 0) {
							com3.setModel(new DefaultComboBoxModel<>(s2));
						} else
							com3.setModel(new DefaultComboBoxModel<>(s));
					} else
						com3.setModel(new DefaultComboBoxModel<>(e));
				}
			});
			com2.setModel(new DefaultComboBoxModel(
					new String[] { "01", "02", "03", "04", "05", "06", "07",
							"08", "09", "10", "11", "12" }));
			com2.setPreferredSize(new Dimension(50, 25));
			com2.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return com2;
	}

	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("월");
			label_2.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_2;
	}

	private JComboBox getCom3() {
		if (com3 == null) {
			com3 = new JComboBox();
			com3.setModel(new DefaultComboBoxModel(new String[] { "01", "02",
					"03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
					"13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
					"23", "24", "25", "26", "27", "28", "29", "30", "31" }));
			com3.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return com3;
	}

	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("일");
			label_3.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_3;
	}

	private JPanel getPanel_8() {
		if (panel_8 == null) {
			panel_8 = new JPanel();
			panel_8.setLayout(new BorderLayout(0, 0));
			panel_8.add(getLblNewLabel_5(), BorderLayout.WEST);
			panel_8.add(getPanel_27(), BorderLayout.CENTER);
		}
		return panel_8;
	}

	private JPanel getPanel_9() {
		if (panel_9 == null) {
			panel_9 = new JPanel();
			panel_9.setLayout(new BorderLayout(0, 0));
			panel_9.add(getPanel_18(), BorderLayout.SOUTH);
		}
		return panel_9;
	}

	private JPanel getPanel_17() {
		if (panel_17 == null) {
			panel_17 = new JPanel();
			panel_17.setLayout(new BorderLayout(0, 0));
			panel_17.add(getFindStr());
			panel_17.add(getButton(), BorderLayout.EAST);
		}
		return panel_17;
	}

	private JPanel getPanel_18() {
		if (panel_18 == null) {
			panel_18 = new JPanel();
			panel_18.setLayout(new BorderLayout(0, 0));
			panel_18.add(getLblNewLabel_4(), BorderLayout.WEST);
			panel_18.add(getPanel_19(), BorderLayout.CENTER);
			panel_18.add(getPanel_21(), BorderLayout.SOUTH);
		}
		return panel_18;
	}

	private JLabel getLblNewLabel_4() {
		if (lblNewLabel_4 == null) {
			lblNewLabel_4 = new JLabel("조회내용");
			lblNewLabel_4.setFont(new Font("나눔고딕코딩", Font.PLAIN, 18));
			lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel_4.setPreferredSize(new Dimension(90, 30));
		}
		return lblNewLabel_4;
	}

	private JPanel getPanel_19() {
		if (panel_19 == null) {
			panel_19 = new JPanel();
			panel_19.setLayout(new BorderLayout(0, 0));
			panel_19.add(getPanel_20(), BorderLayout.WEST);
		}
		return panel_19;
	}

	private JPanel getPanel_20() {
		if (panel_20 == null) {
			panel_20 = new JPanel();

			panel_20.add(getBtn1());
			panel_20.add(getBtn2());
			bg.add(btn1);
			bg.add(btn2);
		}
		return panel_20;
	}

	private JRadioButton getBtn1() {
		if (btn1 == null) {
			btn1 = new JRadioButton("제품별 판매량 조회");
		}
		return btn1;
	}

	private JRadioButton getBtn2() {
		if (btn2 == null) {
			btn2 = new JRadioButton("모든 판매 기록");
			btn2.setSelected(true);
		}
		return btn2;
	}

	private JPanel getPanel_21() {
		if (panel_21 == null) {
			panel_21 = new JPanel();
			panel_21.setLayout(new BorderLayout(0, 0));
			panel_21.add(getLabel_4(), BorderLayout.WEST);
			panel_21.add(getPanel_22(), BorderLayout.CENTER);
		}
		return panel_21;
	}

	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("출력순서");
			label_4.setPreferredSize(new Dimension(90, 30));
			label_4.setHorizontalAlignment(SwingConstants.CENTER);
			label_4.setFont(new Font("나눔고딕코딩", Font.PLAIN, 18));
		}
		return label_4;
	}

	private JPanel getPanel_22() {
		if (panel_22 == null) {
			panel_22 = new JPanel();
			panel_22.setLayout(new BorderLayout(0, 0));
			panel_22.add(getPanel_23(), BorderLayout.WEST);
		}
		return panel_22;
	}

	private JPanel getPanel_23() {
		if (panel_23 == null) {
			panel_23 = new JPanel();
			panel_23.add(getBtn3());
			panel_23.add(getBtn4());
			bg2.add(btn3);
			bg2.add(btn4);
		}
		return panel_23;
	}

	private JRadioButton getBtn3() {
		if (btn3 == null) {
			btn3 = new JRadioButton("최근 판매기록이 위로");
			btn3.setSelected(true);
		}
		return btn3;
	}

	private JRadioButton getBtn4() {
		if (btn4 == null) {
			btn4 = new JRadioButton("과거 판매내역이 위로");
		}
		return btn4;
	}

	private JPanel getPanel_24() {
		if (panel_24 == null) {
			panel_24 = new JPanel();
			panel_24.add(getBtnSave());
			panel_24.add(getBtnPrint());
			panel_24.add(getPanel_25());
		}
		return panel_24;
	}

	private JPanel getPanel_25() {
		if (panel_25 == null) {
			panel_25 = new JPanel();
			panel_25.setPreferredSize(new Dimension(50, 10));
		}
		return panel_25;
	}

	private JPanel getPanel_26() {
		if (panel_26 == null) {
			panel_26 = new JPanel();
			panel_26.setPreferredSize(new Dimension(240, 10));
		}
		return panel_26;
	}

	private JLabel getLblNewLabel_5() {
		if (lblNewLabel_5 == null) {
			lblNewLabel_5 = new JLabel(" ~ ");
		}
		return lblNewLabel_5;
	}

	private JPanel getPanel_27() {
		if (panel_27 == null) {
			panel_27 = new JPanel();
			panel_27.setLayout(new BorderLayout(0, 0));
			panel_27.add(getPanel_28(), BorderLayout.WEST);
		}
		return panel_27;
	}

	private JPanel getPanel_28() {
		if (panel_28 == null) {
			panel_28 = new JPanel();
			panel_28.add(getCom4());
			panel_28.add(getLabel_5());
			panel_28.add(getCom5());
			panel_28.add(getLabel_6());
			panel_28.add(getCom6());
			panel_28.add(getLabel_7());
			panel_28.add(getButton_1());
		}
		return panel_28;
	}

	private JComboBox getCom4() {
		if (com4 == null) {
			com4 = new JComboBox();
			com4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (Integer.parseInt((String) com4.getSelectedItem()) % 4 == 0) {
						if (com5.getSelectedItem().equals("02")) {
							com6.setModel(new DefaultComboBoxModel<>(s2));
						}
					} else
						com6.setModel(new DefaultComboBoxModel<>(s));
				}
			});
			com4.setPreferredSize(new Dimension(70, 25));
			com4.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return com4;
	}

	private JLabel getLabel_5() {
		if (label_5 == null) {
			label_5 = new JLabel("년");
			label_5.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_5;
	}

	private JComboBox getCom5() {
		if (com5 == null) {
			com5 = new JComboBox();
			com5.setModel(new DefaultComboBoxModel(
					new String[] { "01", "02", "03", "04", "05", "06", "07",
							"08", "09", "10", "11", "12" }));
			com5.setPreferredSize(new Dimension(50, 25));
			com5.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
			com5.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if (com5.getSelectedItem().equals("01")
							|| com5.getSelectedItem().equals("03")
							|| com5.getSelectedItem().equals("05")
							|| com5.getSelectedItem().equals("07")
							|| com5.getSelectedItem().equals("08")
							|| com5.getSelectedItem().equals("10")
							|| com5.getSelectedItem().equals("12")) {
						com6.setModel(new DefaultComboBoxModel<>(h));
					} else if (com5.getSelectedItem().equals("02")) {

						if (Integer.parseInt((String) com4.getSelectedItem()) % 4 == 0) {
							com6.setModel(new DefaultComboBoxModel<>(s2));
						} else {
							com6.setModel(new DefaultComboBoxModel<>(s));
						}
					} else
						com6.setModel(new DefaultComboBoxModel<>(e));
				}
			});

		}
		return com5;
	}

	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("월");
			label_6.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_6;
	}

	private JComboBox getCom6() {
		if (com6 == null) {
			com6 = new JComboBox();
			com6.setModel(new DefaultComboBoxModel(new String[] { "01", "02",
					"03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
					"13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
					"23", "24", "25", "26", "27", "28", "29", "30", "31" }));
			com6.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return com6;
	}

	private JLabel getLabel_7() {
		if (label_7 == null) {
			label_7 = new JLabel("일");
			label_7.setFont(new Font("나눔고딕코딩", Font.PLAIN, 15));
		}
		return label_7;
	}

	public void ExcelSave(JTable table) {// 엑셀 저장하는 메소드(매개변수 JTable)
		try {
			JFileChooser jfc = new JFileChooser();
			int yn = jfc.showSaveDialog(null);
			if (yn == 0) {
				String fileName = jfc.getSelectedFile().toString();// 저장경로 받기
				WritableWorkbook workbook = Workbook.createWorkbook(new File(
						fileName + ".xls"));
				WritableSheet s1 = workbook.createSheet("sheet 0", 0); // 엑셀에
				// 시트생성
				for (int i = 0; i < table.getColumnCount(); i++) {// 열 제목 추가
					Label label = new Label(i, 0, table.getColumnName(i));
					s1.addCell(label);
				}
				// 데이터 저장
				for (int i = 0; i < table.getRowCount(); i++) {// 행 추가
					for (int j = 0; j < table.getColumnCount(); j++) {
						Label label = new Label(j, i + 1,
								(String) table.getValueAt(i, j)); // 라벨객체 생성.
						s1.addCell(label);
					}
				}
				JOptionPane
						.showMessageDialog(null, fileName + ".xls 에 저장되었습니다");// 알림창
				workbook.write(); // 파일로 쓰기
				workbook.close(); // 닫기
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void setD(String y, String m, String d) {
		com1.setSelectedItem(y);
		com2.setSelectedItem(m);
		com3.setSelectedItem(d);
	}

	public void setD2(String y, String m, String d) {
		com4.setSelectedItem(y);
		com5.setSelectedItem(m);
		com6.setSelectedItem(d);
	}

	private JButton getBtnNewButton_6() {
		if (btnNewButton_6 == null) {
			btnNewButton_6 = new JButton("");
			btnNewButton_6.setIcon(new ImageIcon(
					"C:\\Users\\jhta\\Documents\\네이트온 받은 파일\\test.png"));
			btnNewButton_6.setPreferredSize(new Dimension(25, 25));
			btnNewButton_6.setSize(new Dimension(10, 10));
			btnNewButton_6.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					SaleCalendar f = new SaleCalendar(SaleList.this, 1);
					f.main(null);
				}
			});
		}
		return btnNewButton_6;
	}

	private JButton getButton_1() {
		if (button_1 == null) {
			button_1 = new JButton("");
			button_1.setIcon(new ImageIcon(
					"C:\\Users\\jhta\\Documents\\네이트온 받은 파일\\test.png"));
			button_1.setPreferredSize(new Dimension(25, 25));
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					SaleCalendar f = new SaleCalendar(SaleList.this, 2);
					f.main(null);
				}
			});
		}
		return button_1;
	}
}